# -*- makefile -*-
# Makefile for Windows with MinGW 

OBJS = class.o compiler.o database.o replicator.o hashtab.o file.o symtab.o btree.o sync.o \
	cursor.o query.o pagepool.o wwwapi.o w32sock.o blob.o container.o rtree.o exception.o localcli.o

CLI_OBJS = cli.o w32sock.o repsock.o

INCS = gigabase.h stdtp.h class.h database.h cursor.h selection.h reference.h wwwapi.h array.h \
	file.h hashtab.h btree.h sync.h query.h datetime.h pagepool.h blob.h container.h rectangle.h timeseries.h config.h confdefs.h exception.h

CLI_INCS = cli.h


STDLIBS = -lwsock32

VERSION=2
GB_LIB = libgigabase.a
CLI_LIB = libcli.a
EXES = subsql.exe forcerecovery.exe
GB_LIBS=$(GB_LIB)
CLI_LIBS=$(CLI_LIB)

EXAMPLES = guess.exe testdb.exe testleak.exe testjoin.exe testddl.exe testperf.exe testperf2.exe testsync.exe testiref.exe testtrav.exe testidx.exe testidx2.exe clitest.exe localclitest.exe testblob.exe testraw.exe testspat.exe testreplic.exe

WEB_EXAMPLES = cgistub.exe bugdb.exe clidb.exe

CC = g++
# !!! DEFS macro is deprecated - edit config.h header file instead
DEFS =

CFLAGS = -c -Wall -O5 -g $(DEFS)
#CFLAGS = -c -Wall -O0 -g $(DEFS)
#CFLAGS = -c -Wall -O0 -DGIGABASE_DEBUG=DEBUG_TRACE -g $(DEFS)


LD = $(CC)
LDFLAGS = -g $(TFLAGS)

AR = ar
ARFLAGS = -cru

RANLIB = ranlib


all: $(GB_SHARED) $(CLI_SHARED) $(GB_LIB) $(CLI_LIB) $(EXES) $(EXAMPLES)

www: $(GB_SHARED) $(WEB_EXAMPLES)


class.o: class.cpp compiler.h compiler.d symtab.h $(INCS)
	$(CC) $(CFLAGS) class.cpp

compiler.o: compiler.cpp compiler.h compiler.d symtab.h $(INCS)
	$(CC) $(CFLAGS) compiler.cpp

sync.o: sync.cpp sync.h stdtp.h
	$(CC) $(CFLAGS) sync.cpp

query.o: query.cpp compiler.h compiler.d symtab.h $(INCS)
	$(CC) $(CFLAGS) query.cpp

database.o: database.cpp compiler.h compiler.d symtab.h $(INCS)
	$(CC) $(CFLAGS) database.cpp

localcli.o: localcli.cpp compiler.h compiler.d symtab.h localcli.h $(INCS)
	$(CC) $(CFLAGS) localcli.cpp

replicator.o: replicator.cpp replicator.h sockio.h $(INCS)
	$(CC) $(CFLAGS) replicator.cpp

cursor.o: cursor.cpp compiler.h compiler.d $(INCS)
	$(CC) $(CFLAGS) cursor.cpp

hashtab.o: hashtab.cpp $(INCS)
	$(CC) $(CFLAGS) hashtab.cpp

pagepool.o: pagepool.cpp $(INCS)
	$(CC) $(CFLAGS) pagepool.cpp

file.o: file.cpp $(INCS)
	$(CC) $(CFLAGS) file.cpp

symtab.o: symtab.cpp symtab.h $(INCS)
	$(CC) $(CFLAGS) symtab.cpp

btree.o: btree.cpp $(INCS)
	$(CC) $(CFLAGS) btree.cpp

rtree.o: rtree.cpp $(INCS)
	$(CC) $(CFLAGS) rtree.cpp

exception.o: exception.cpp $(INCS)
	$(CC) $(CFLAGS) exception.cpp

blob.o: blob.cpp $(INCS)
	$(CC) $(CFLAGS) blob.cpp

container.o: container.cpp $(INCS)
	$(CC) $(CFLAGS) container.cpp

wwwapi.o: wwwapi.cpp wwwapi.h sockio.h stdtp.h sync.h
	$(CC) $(CFLAGS) wwwapi.cpp

w32sock.o: w32sock.cpp w32sock.h sockio.h stdtp.h
	$(CC) $(CFLAGS) w32sock.cpp

repsock.o: repsock.cpp repsock.h sockio.h stdtp.h sync.h
	$(CC) $(CFLAGS) repsock.cpp

cli.o: cli.cpp cli.h cliproto.h repsock.h sockio.h stdtp.h sync.h
	$(CC) $(CFLAGS) cli.cpp

libgigabase.a: $(OBJS)
	-del libgigabase.a
	$(AR) $(ARFLAGS) libgigabase.a $(OBJS)
	$(RANLIB) libgigabase.a

libcli.a: $(CLI_OBJS)
	-del libcli.a
	$(AR) $(ARFLAGS) libcli.a $(CLI_OBJS)
	$(RANLIB) libcli.a


clitest.o: clitest.c cli.h
	$(CC) $(CFLAGS) clitest.c

clitest.exe: clitest.o $(CLI_LIB)
	$(LD) $(LDFLAGS) -o clitest.exe clitest.o $(CLI_LIBS) $(STDLIBS) $(SOCKLIBS)

localclitest.exe: clitest.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o localclitest.exe clitest.o $(GB_LIBS) $(STDLIBS)

subsql.o: subsql.cpp subsql.h compiler.h compiler.d symtab.h $(INCS)
	$(CC) $(CFLAGS) subsql.cpp

server.o: server.cpp server.h cli.h cliproto.h subsql.h compiler.h compiler.d symtab.h $(INCS)
	$(CC) $(CFLAGS) server.cpp

subsql.exe: subsql.o server.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o subsql.exe subsql.o server.o $(GB_LIBS) $(STDLIBS) $(SOCKLIBS)

bugdb.o: bugdb.cpp bugdb.h $(INCS)
	$(CC) $(CFLAGS) bugdb.cpp

bugdb.exe: bugdb.o  $(GB_LIB)
	$(LD) $(LDFLAGS) -o bugdb.exe bugdb.o $(GB_LIBS) $(STDLIBS) $(SOCKLIBS)

clidb.o: clidb.cpp clidb.h $(INCS)
	$(CC) $(CFLAGS) clidb.cpp

clidb.exe: clidb.o  $(GB_LIB)
	$(LD) $(LDFLAGS) -o clidb.exe clidb.o $(GB_LIBS) $(STDLIBS) $(SOCKLIBS)

forcerecovery.o: forcerecovery.cpp database.h
	$(CC) $(CFLAGS) forcerecovery.cpp 

forcerecovery.exe: forcerecovery.o
	$(LD) $(LDFLAGS)  -o forcerecovery.exe forcerecovery.o

cgistub.o: cgistub.cpp stdtp.h sockio.h
	$(CC) $(CFLAGS) cgistub.cpp

cgistub.exe: cgistub.o
	$(LD) $(LDFLAGS) -o cgistub.exe cgistub.o $(GB_LIBS) $(STDLIBS) $(SOCKLIBS)

guess.o: guess.cpp $(INCS)
	$(CC) $(CFLAGS) guess.cpp

guess.exe: guess.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o guess.exe guess.o $(GB_LIBS) $(STDLIBS)

testdb.o: testdb.cpp $(INCS)
	$(CC) $(CFLAGS) testdb.cpp

testdb.exe: testdb.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testdb.exe testdb.o $(GB_LIBS) $(STDLIBS)

testraw.o: testraw.cpp $(INCS)
	$(CC) $(CFLAGS) testraw.cpp

testraw.exe: testraw.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testraw.exe testraw.o $(GB_LIBS) $(STDLIBS)

testleak.o: testleak.cpp $(INCS)
	$(CC) $(CFLAGS) testleak.cpp

testleak.exe: testleak.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testleak.exe testleak.o $(GB_LIBS) $(STDLIBS)

testjoin.o: testjoin.cpp $(INCS)
	$(CC) $(CFLAGS) testjoin.cpp

testjoin.exe: testjoin.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testjoin.exe testjoin.o $(GB_LIBS) $(STDLIBS)

testddl.o: testddl.cpp $(INCS)
	$(CC) $(CFLAGS) testddl.cpp

testddl.exe: testddl.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testddl.exe testddl.o $(GB_LIBS) $(STDLIBS)

testblob.o: testblob.cpp $(INCS)
	$(CC) $(CFLAGS) testblob.cpp

testblob.exe: testblob.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testblob.exe testblob.o $(GB_LIBS) $(STDLIBS)

testperf.o: testperf.cpp $(INCS)
	$(CC) $(CFLAGS) testperf.cpp

testperf.exe: testperf.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testperf.exe testperf.o $(GB_LIBS) $(STDLIBS)

testspat.o: testspat.cpp $(INCS)
	$(CC) $(CFLAGS) testspat.cpp

testspat.exe: testspat.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testspat.exe testspat.o $(GB_LIBS) $(STDLIBS)

testreplic.o: testreplic.cpp replicator.h $(INCS)
	$(CC) $(CFLAGS) testreplic.cpp

testreplic.exe: testreplic.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testreplic.exe testreplic.o $(GB_LIB) $(STDLIBS) $(SOCKLIBS)

testinc.o: testinc.cpp $(INCS)
	$(CC) $(CFLAGS) testinc.cpp

testinc.exe: testinc.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testinc.exe testinc.o $(GB_LIBS) $(STDLIBS)

testperf2.o: testperf2.cpp $(INCS)
	$(CC) $(CFLAGS) testperf2.cpp

testperf2.exe: testperf2.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testperf2.exe testperf2.o $(GB_LIBS) $(STDLIBS)

testidx.o: testidx.cpp $(INCS)
	$(CC) $(CFLAGS) testidx.cpp

testidx.exe: testidx.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testidx.exe testidx.o $(GB_LIBS) $(STDLIBS)

testidx2.o: testidx2.cpp $(INCS)
	$(CC) $(CFLAGS) testidx2.cpp

testidx2.exe: testidx2.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testidx2.exe testidx2.o $(GB_LIBS) $(STDLIBS)

testsync.o: testsync.cpp $(INCS)
	$(CC) $(CFLAGS) testsync.cpp

testsync.exe: testsync.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testsync.exe testsync.o $(GB_LIBS) $(STDLIBS)

testiref.o: testiref.cpp $(INCS)
	$(CC) $(CFLAGS) testiref.cpp

testiref.exe: testiref.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testiref.exe testiref.o $(GB_LIBS) $(STDLIBS)

testtrav.o: testtrav.cpp $(INCS)
	$(CC) $(CFLAGS) testtrav.cpp

testtrav.exe: testtrav.o $(GB_LIB)
	$(LD) $(LDFLAGS) -o testtrav.exe testtrav.o $(GB_LIBS) $(STDLIBS)

java: javacli.jar CliTest.class

javacli.jar: javacli/*.java
	javac -g javacli/*.java
	jar cvf javacli.jar javacli/*.class
	javadoc -public javacli

CliTest.class: CliTest.java javacli.jar
	javac CliTest.java

cleanobj:
	-del *.o
	-del javacli/*.class 
	-del *.jar 
	-del *.class  

cleandbs:
	-del *.dbs


clean: cleanobj cleandbs
	-del *.a
	-del *.exe

